package com.cskaoyan.service.front;

import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.po.MarketCategoryExample;
import com.cskaoyan.bean.vo.front.FrontShowGoodsCategoryVO;
import com.cskaoyan.bean.vo.front.ShowBrandVO;
import com.cskaoyan.bean.vo.front.ShowIndexVO;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther 10-何兴绕
 * @Date 2022年10月14日 15:53
 */
@Service
public class CatalogServiceImpl implements CatalogService {

    @Autowired
    MarketCategoryMapper categoryMapper;

    @Override
    public ShowIndexVO showIndex() {
        MarketCategoryExample example = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = example.createCriteria();
        criteria.andPidEqualTo(0);
        criteria.andDeletedEqualTo(false);
        List<MarketCategory> marketCategories = categoryMapper.selectByExample(example);
        MarketCategory marketCategory = marketCategories.get(0);

        MarketCategoryExample subCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria subCategoryExampleCriteria = subCategoryExample.createCriteria();
        subCategoryExampleCriteria.andPidEqualTo(marketCategory.getId());
        List<MarketCategory> subCategory = categoryMapper.selectByExample(subCategoryExample);


        ShowIndexVO showIndexVO = new ShowIndexVO();
        showIndexVO.setCurrentCategory(marketCategory);
        showIndexVO.setCategoryList(marketCategories);
        showIndexVO.setCurrentSubCategory(subCategory);
        return showIndexVO;
    }

    @Override
    public FrontShowGoodsCategoryVO showGoodsCategory(Integer id) {
        MarketCategory firstCategory = categoryMapper.selectByPrimaryKey(id);
        MarketCategoryExample example = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = example.createCriteria();
        criteria.andPidEqualTo(id);
        List<MarketCategory> secondCategories = categoryMapper.selectByExample(example);
        FrontShowGoodsCategoryVO frontShowGoodsCategoryVO = new FrontShowGoodsCategoryVO();
        frontShowGoodsCategoryVO.setCurrentCategory(firstCategory);
        frontShowGoodsCategoryVO.setCurrentSubCategory(secondCategories);
        return frontShowGoodsCategoryVO;
    }
}
